package forth_exp;

import java.util.ArrayList;

public class SongGameMain {
    public static void main(String[] args)
    {
        SongGame songGame = new SongGame();
        for(int i = 0;i < 10;i++){
            songGame.addSinger(80 + i);
        }
        System.out.println(songGame.ComputeAverage());

        SchoolExam schoolExam = new SchoolExam();
        for(int i = 0;i < 10;i++){
            schoolExam.addStudent(80 + i);
        }
        System.out.println(schoolExam.ComputeAverage());
    }
}

interface ComputeAverage
{
    double ComputeAverage();
}

class SongGame implements ComputeAverage
{
    ArrayList<Double> singers;
    public SongGame() {
        singers = new ArrayList<Double>(10);
    }

    @Override
    public double ComputeAverage()
    {
        if(singers.isEmpty()){
            return 0;
        }
        double sum = 0;
        for(double s: singers){
            sum += s;
        }
        return sum / singers.size();
    }

    public void addSinger(double score) {
        singers.add(score);
    }
    public ArrayList<Double> getSingers() {
        return new ArrayList<>(singers); // 返回副本以保护原始数据
    }

}

class SchoolExam implements ComputeAverage {
    ArrayList<Double> students; // 修正泛型为 Double

    public SchoolExam() {
        students = new ArrayList<>(10); // 初始化
    }
    @Override
    public double ComputeAverage() {
        if (students.isEmpty()) {
            return 0; // 避免除零
        }
        double sum = 0;
        for (double s : students) {
            sum += s;
        }
        return sum / students.size(); // 使用 size() 方法
    }
    public void addStudent(double score) {
        students.add(score);
    }
    public ArrayList<Double> getStudents() {
        return new ArrayList<>(students); // 返回副本以保护原始数据
    }
}

